//
//  ByDocumentarySetChooseView.m
//  caipiao_ios
//
//  Created by mc on 2018/8/18.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentarySetChooseView.h"

@implementation ByDocumentarySetChooseView

- (id)init{
    self = [super init];
    if (self) {
        
        CGFloat width = SCREEN_WIDTH - 12 - 121 - 20;
        CGFloat magin = 10;
        width = (width - magin * 2) / 3.0;
        self.index = 0;
        for (int i = 0; i < 3; i++) {
            UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [self addSubview:leftBtn];
            [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self).offset((width + magin) * i);
                make.centerY.equalTo(self).offset(0);
                make.size.mas_equalTo(CGSizeMake(width, 27));
            }];
            leftBtn.titleLabel.font = FONT(12);
            leftBtn.tag = 100 + i;
            [leftBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            if (i == 0) {
                
                leftBtn.backgroundColor = BY_THEME_COLOR;
                [leftBtn setTitle:@"公开" forState:UIControlStateNormal];
                [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                
            }else{
                
                leftBtn.layer.borderWidth = 1;
                leftBtn.layer.borderColor = BY_LINE_COLOR.CGColor;
                [leftBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
                if (i == 1) {
                    [leftBtn setTitle:@"开奖可见" forState:UIControlStateNormal];
                }else{
                    [leftBtn setTitle:@"永久保密" forState:UIControlStateNormal];
                }
            }
          
        }
    }
    return self;
}

- (void)btnAction:(UIButton *)btn{
    
    if (btn.tag - 100 != self.index) {
        for (int i = 0; i < 3; i++){
            
            UIButton *btn = [self viewWithTag:i + 100];
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = BY_LINE_COLOR.CGColor;
            [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            btn.backgroundColor = [UIColor whiteColor];
        }
        
        btn.backgroundColor = BY_THEME_COLOR;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        if (self.indexAtView) {
            self.indexAtView(btn.tag - 100);
        }
        self.index = btn.tag - 100;
    
    }
}

@end
